//package cn.iocoder.yudao.module.handguard.tool.http;
//
//import javax.imageio.ImageIO;
//import java.awt.*;
//import java.awt.image.BufferedImage;
//import java.io.File;
//import java.io.IOException;
//
//public class ImageProcessorAWT {
//
//    public static BufferedImage grayScale(BufferedImage image) {
//        BufferedImage grayImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
//        Graphics2D g2 = grayImage.createGraphics();
//        g2.drawImage(image, 0, 0, null);
//        g2.dispose();
//        return grayImage;
//    }
//
//    public static BufferedImage binaryThreshold(BufferedImage image, int threshold) {
//        BufferedImage binaryImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_BINARY);
//        for (int i = 0; i < image.getWidth(); i++) {
//            for (int j = 0; j < image.getHeight(); j++) {
//                int pixel = image.getRGB(i, j);
//                int gray = (int) ((pixel >> 16 & 0xff) * 0.299 + (pixel >> 8 & 0xff) * 0.587 + (pixel & 0xff) * 0.114);
//                if (gray > threshold) {
//                    binaryImage.setRGB(i, j, Color.white.getRGB());
//                } else {
//                    binaryImage.setRGB(i, j, Color.black.getRGB());
//                }
//            }
//        }
//        return binaryImage;
//    }
//
//    public static void main(String[] args) throws IOException {
//        BufferedImage originalImage = ImageIO.read(new File("/Users/handsome/LDFC/img/ca0b973bb6b47ef76ca569d8ae856599.jpeg"));
//        BufferedImage grayImage = grayScale(originalImage);
//        BufferedImage binaryImage = binaryThreshold(grayImage, 248); // 阈值可以根据实际情况调整
//        System.out.println(binaryImage);
//        // 保存或显示处理后的图片
////        ImageIO.write(grayImage, "jpg", new File("path_to_gray_image.jpg"));
////        ImageIO.write(binaryImage, "jpg", new File("path_to_binary_image.jpg"));
//    }
//}